package com.tsvetanv.data.binding.nested.collections.array;

import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.web.bind.ServletRequestDataBinder;

import com.tsvetanv.data.binding.model.nested.NestedArrayStringCommandBean;

import junit.framework.TestCase;

public class NestedArrayStringBindTest extends TestCase {

	private NestedArrayStringCommandBean bean;
	private ServletRequestDataBinder binder;
	private MockHttpServletRequest request;

	protected void setUp() throws Exception {
		bean = new NestedArrayStringCommandBean();
		binder = new ServletRequestDataBinder(bean, "beanName");
		request = new MockHttpServletRequest();
	}

	public void testNestedArrayStringBind() {
		request.addParameter("strings[2]", "Tsvetan");
		request.addParameter("strings[0]", "Vasilev");

		binder.bind(request);

		assertEquals("Tsvetan", bean.getStrings()[2]);
		assertEquals("Vasilev", bean.getStrings()[0]);
		assertNull(bean.getStrings()[1]);
	}
}
